﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace DIProject.ReceptionGoods
{
    public partial class AddWaybillsrecord : Form
    {
        private DataSets.waybillsData.ContragentsLinksRow _selRow;
        /// <summary>
        /// выбранный товар
        /// </summary>
        public DataSets.waybillsData.ContragentsLinksRow SelectedGood
        {
            get
            {
                if (_selRow == null)
                    throw new Util.DIException("Ошибка. Не выбран товар.");
                return _selRow;
            }
            set
            {
                _selRow = value;
            }
        }
        private Int32 _sellerId;
        /// <summary>
        /// текущий поставщик
        /// </summary>
        public Int32 SellerId
        {
            get { return _sellerId; }
            set { _sellerId = value; }
        }

        public AddWaybillsrecord(DataSets.waybillsData.ContragentsLinksRow cr)
        {
            SelectedGood = cr;
            InitializeComponent();
        }

        private void textBox1_Validating(object sender, CancelEventArgs e)
        {
            TextBox tb = sender as TextBox;
            if (tb != null)
                e.Cancel = !Util.Validator.Int32Validation(tb, string.Empty);
        }

        private void txbMarkUp_Validating(object sender, CancelEventArgs e)
        {
            TextBox tb = sender as TextBox;
            if (tb != null)
                e.Cancel = !Util.Validator.DoubleValidation(tb, string.Empty);
        }

        private void txbRetailPrice_Validating(object sender, CancelEventArgs e)
        {
            TextBox tb = sender as TextBox;
            if (tb != null)
                e.Cancel = !Util.Validator.DecimalValidation(tb, string.Empty);
        }

        private void txbSupplierPrice_Validating(object sender, CancelEventArgs e)
        {
            TextBox tb = sender as TextBox;
            if (tb != null)
                e.Cancel = !Util.Validator.DecimalValidation(tb, string.Empty);
        }

        private void txbNDSTax_Validating(object sender, CancelEventArgs e)
        {
            TextBox tb = sender as TextBox;
            if (tb != null)
                e.Cancel = !Util.Validator.DoubleValidation(tb, string.Empty);
        }

        private void txbNDSSumm_Validating(object sender, CancelEventArgs e)
        {
            TextBox tb = sender as TextBox;
            if (tb != null)
                e.Cancel = !Util.Validator.DoubleValidation(tb, string.Empty);
        }

        private void AddWaybillsrecord_Load(object sender, EventArgs e)
        {
            this.txbName.Text = this.SelectedGood.InnerGoodName;
            DataSets.waybillsDataTableAdapters.SetificatedOrgTableAdapter adapter = new DIProject.DataSets.waybillsDataTableAdapters.SetificatedOrgTableAdapter();
            DataSets.waybillsData.SetificatedOrgDataTable st = adapter.GetData();
            DataSets.waybillsData.SetificatedOrgRow sr = st.NewSetificatedOrgRow();
            sr.Id = Int32.MinValue;
            cbCertificateOrg.DataSource = st;
        }

        private void txbImportMarkUp_Validating(object sender, CancelEventArgs e)
        {
            TextBox tb = sender as TextBox;
            if((tb!=null)&&(!string.IsNullOrEmpty(tb.Text)))
                e.Cancel = !Util.Validator.DoubleValidation(tb,string.Empty);
        }

        private void txbManufacturerPrice_Validating(object sender, CancelEventArgs e)
        {
            TextBox tb = sender as TextBox;
            if ((tb != null) && (!string.IsNullOrEmpty(tb.Text)))
                e.Cancel = !Util.Validator.DoubleValidation(tb, string.Empty);
        }

        private void txbSupplierMarkUp_Validating(object sender, CancelEventArgs e)
        {
            TextBox tb = sender as TextBox;
            if ((tb != null) && (!string.IsNullOrEmpty(tb.Text)))
                e.Cancel = !Util.Validator.DoubleValidation(tb, string.Empty);
        }

        private void button2_Click(object sender, EventArgs e)
        {

        }
    }
}